package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.ShopServerByIdEntity;
import com.egg.ylt.presenter.IShopServerPresenter;
import com.egg.ylt.view.IShopServerView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by sichaoqi on 2018/9/4.
 */

public class ShopServerPresenterImpl extends BasePresenter<IShopServerView> implements IShopServerPresenter {

    @Override
    public void getService(String token, String id, String shopId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("id", id);
        hashMap.put("shopId", shopId);
        RequestManager.getInstance().requestPostByAsyn(API.GET_SHOP_SERVER_BY_ID, hashMap,
                new ReqCallBack<ShopServerByIdEntity>() {

                    @Override
                    public void onReqSuccess(ShopServerByIdEntity shopServerByIdEntity) {
                        mView.dismissDialogLoading();
                        mView.getServiceData(shopServerByIdEntity);
                    }

                    @Override
                    public void onFailure(String result) {
                        mView.dismissDialogLoading();
//                mView.showError(result);
                        CommonUtils.makeEventToast(mContext, result, false);
                    }

                    @Override
                    public void onReqFailed(ErrorBean error) {
                        mView.dismissDialogLoading();
//                mView.showException(error.toString());
                        CommonUtils.makeEventToast(mContext, error.getMsg(), false);
                    }
                });
    }

    @Override
    public void setCancelMessage(String token, String shopId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("messageId", shopId);
        RequestManager.getInstance().requestPostByAsyn(API.POST_CANCEL_MESSAGE, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.cancelCollect();
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
//                mView.showError(result);
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
//                mView.showException(error.toString());
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void setCollectMessage(String token, String shopId, String companyId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("messageId", shopId);
        hashMap.put("companyId", companyId);
        //0 为咨询标识，1为门店详情
        hashMap.put("collectType", "1");
        RequestManager.getInstance().requestPostByAsyn(API.POST_COLLECT_MESSAGE, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.doCollect();
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
//                mView.showError(result);
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
//                mView.showException(error.toString());
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
